package com.example.demo;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;

@Component
public class KafkaSender {
	
	@Autowired private KafkaTemplate<String, String> kafkaTemplate;
	
	public void send() {
		Message message = new Message(System.currentTimeMillis(), "发送一条消息", new Date());
		
		kafkaTemplate.send(KafkaConfig.TOPICS_SEND_MESSAGE, JSONObject.toJSONString(message));
	}
}
